<template>
  <div class="memo">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="250px">
        <div class="aside-form">
          <div class="aside-form-input">
            <el-input
              v-model="newTodoList"
              size="small"
              placeholder="添加待办清单"
            ></el-input>
          </div>
          <el-button
            type="primary"
            icon="el-icon-check"
            circle
            size="mini"
          ></el-button>
        </div>

        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          @select="handleSelect"
        >
          <el-menu-item
            v-for="li in todoList"
            :key="li.index"
            :index="li.index"
          >
            {{ li.title }}
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 清单内容 -->
      <el-container>
        <el-header style="height: auto">
          {{ todoList[activeIndex].title }}
        </el-header>

        <!-- 待办事项三个泳道 -->
        <el-main>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-card shadow="never" class="todolist-lane todo-lane">
                <div slot="header" class="clearfix">
                  <span>To Do</span>
                  <el-button class="card-header-btn" type="text">
                    添加待办
                  </el-button>
                </div>

                <!-- 待办卡片 -->
                <el-card
                  shadow="hover"
                  class="todolist-card"
                  v-for="(todo, i) in todoList[activeIndex].content.todo"
                  :key="i"
                >
                  <div slot="header" class="clearfix">
                    <el-checkbox
                      v-model="todo.isComplete"
                      disabled
                    ></el-checkbox>
                    {{ todo.farItem }}
                    <el-button class="el-icon-more card-header-btn" type="text">
                    </el-button>
                  </div>

                  <ul class="el-menu tlcard-list">
                    <li
                      v-for="(tdChl, iChl) in todo.child"
                      :key="iChl"
                      class="tlcard-list-item"
                    >
                      <el-checkbox
                        v-model="tdChl.isComplete"
                        class="card-item-checkbox"
                        disabled
                      ></el-checkbox>
                      <p>{{ tdChl.item }}</p>
                    </li>
                  </ul>
                  <div class="tlcard-footer">
                    <span class="tlcard-date">{{ todo.endDate }}</span>
                    <span class="tlcard-time">{{ todo.endTime }}</span>
                    <!-- <el-button
                      class="el-icon-s-order tlcard-arch tlcard-right-btn"
                      type="text"
                      title="卡片未点亮，不可归档"
                      @click="msg('卡片还没点亮，不可归档', 'warning')"
                    ></el-button> -->
                    <el-button
                      class="el-icon-user tlcard-work tlcard-right-btn"
                      type="text"
                      title="点亮卡片"
                      @click="openCard(i)"
                    ></el-button>
                  </div>
                </el-card>
              </el-card>
            </el-col>

            <el-col :span="8">
              <el-card shadow="never" class="todolist-lane doing-lane">
                <div slot="header" class="clearfix">
                  <span>Doing</span>
                  <!-- <el-button class="card-header-btn" type="text">
                    添加待办
                  </el-button> -->
                </div>

                <!-- 待办卡片 -->
                <el-card
                  shadow="hover"
                  class="todolist-card"
                  v-for="(doing, i) in todoList[activeIndex].content.doing"
                  :key="i"
                >
                  <div slot="header" class="clearfix">
                    <el-checkbox
                      v-model="doing.isComplete"
                      @change="farCheckChange('doing', i)"
                    ></el-checkbox>
                    {{ doing.farItem }}
                    <el-button class="el-icon-more card-header-btn" type="text">
                    </el-button>
                  </div>

                  <ul class="el-menu tlcard-list">
                    <li
                      v-for="(tdChl, iChl) in doing.child"
                      :key="iChl"
                      class="tlcard-list-item"
                    >
                      <el-checkbox
                        v-model="tdChl.isComplete"
                        class="card-item-checkbox"
                      ></el-checkbox>
                      <p>{{ tdChl.item }}</p>
                    </li>
                  </ul>
                  <div class="tlcard-footer">
                    <span class="tlcard-date">{{ doing.endDate }}</span>
                    <span class="tlcard-time">{{ doing.endTime }}</span>
                    <!-- <el-button
                      class="el-icon-s-order tlcard-arch tlcard-right-btn"
                      type="text"
                      title="完成卡片才可归档"
                      @click="msg('卡片尚没完成，不可归档', 'warning')"
                    ></el-button> -->
                    <el-button
                      class="el-icon-user-solid tlcard-work tlcard-right-btn"
                      type="text"
                      title="熄灭卡片"
                      @click="closeCard(i)"
                    ></el-button>
                  </div>
                </el-card>
              </el-card>
            </el-col>

            <el-col :span="8">
              <el-card shadow="never" class="todolist-lane done-lane">
                <div slot="header" class="clearfix">
                  <span>Done</span>
                  <!-- <el-button class="card-header-btn" type="text">
                    添加待办
                  </el-button> -->
                </div>

                <!-- 待办卡片 -->
                <el-card
                  shadow="hover"
                  class="todolist-card"
                  v-for="(done, i) in todoList[activeIndex].content.done"
                  :key="i"
                >
                  <div slot="header" class="clearfix">
                    <el-checkbox
                      v-model="done.isComplete"
                      @change="farCheckChange('done', i)"
                    ></el-checkbox>
                    {{ done.farItem }}
                    <el-button class="el-icon-more card-header-btn" type="text">
                    </el-button>
                  </div>

                  <ul class="el-menu tlcard-list">
                    <li
                      v-for="(tdChl, iChl) in done.child"
                      :key="iChl"
                      class="tlcard-list-item"
                    >
                      <el-checkbox
                        v-model="tdChl.isComplete"
                        class="card-item-checkbox"
                        disabled
                      ></el-checkbox>
                      <p>{{ tdChl.item }}</p>
                    </li>
                  </ul>
                  <div class="tlcard-footer">
                    <span class="tlcard-date">{{ done.endDate }}</span>
                    <span class="tlcard-time">{{ done.endTime }}</span>
                    <el-popconfirm
                      title="确定将卡片归档吗？"
                      @confirm="archiveCard(i)"
                    >
                      <!-- <el-button
                        class="el-icon-s-order tlcard-arch"
                        type="text"
                        title="归档"
                        slot="reference"
                      ></el-button> -->
                      <label for="arch-btn" slot="reference"></label>
                    </el-popconfirm>
                    <el-button
                      class="el-icon-s-order tlcard-arch tlcard-right-btn"
                      type="text"
                      title="归档"
                      id="arch-btn"
                    ></el-button>
                    <span class="tlcard-right-btn complete-count">
                      <!-- <span class="el-icon-finished"></span> -->
                      <i class="el-icon-finished"></i>
                      <span>
                        {{ done.child.filter((it) => it.isComplete).length }}/{{
                          done.child.length
                        }}
                      </span>
                    </span>
                    <!-- <el-button
                      class="el-icon-user-solid tlcard-work tlcard-right-btn"
                      type="text"
                      title="卡片已完成"
                      @click="msg('卡片已完成，不可熄灭', 'warning')"
                    ></el-button> -->
                  </div>
                </el-card>
              </el-card>
            </el-col>
          </el-row>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// import HelloWorld from "@/components/HelloWorld.vue";

export default {
  name: "Memo",
  //   components: {
  //     HelloWorld,
  //   },
  data() {
    return {
      activeIndex: "0",
      newTodoList: "",
      todoList: [
        {
          title: "开发",
          index: "0",
          content: {
            todo: [
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题", isComplete: true },
                  { item: "修改表格样式", isComplete: false },
                  { item: "完善弹窗", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "17:30:00",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题111", isComplete: true },
                  { item: "修改表格样式111", isComplete: false },
                  { item: "完善弹窗111", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
            ],
            doing: [
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题", isComplete: true },
                  { item: "修改表格样式", isComplete: false },
                  { item: "完善弹窗", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题111", isComplete: true },
                  { item: "修改表格样式111", isComplete: false },
                  { item: "完善弹窗111", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
            ],
            done: [
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题", isComplete: true },
                  { item: "修改表格样式", isComplete: false },
                  { item: "完善弹窗", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: true,
              },
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题111", isComplete: true },
                  { item: "修改表格样式111", isComplete: false },
                  { item: "完善弹窗111", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: true,
              },
            ],
          },
        },
        {
          title: "杂七杂八",
          index: "1",
          content: {
            todo: [
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题", isComplete: true },
                  { item: "修改表格样式", isComplete: false },
                  { item: "完善弹窗", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题111", isComplete: true },
                  { item: "修改表格样式111", isComplete: false },
                  { item: "完善弹窗111", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
            ],
            doing: [],
            done: [],
          },
        },
        {
          title: "其他",
          index: "2",
          content: {
            todo: [
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题", isComplete: true },
                  { item: "修改表格样式", isComplete: false },
                  { item: "完善弹窗", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
              {
                farItem: "定时任务管理页",
                annotation: "",
                child: [
                  { item: "修改页面标题111", isComplete: true },
                  { item: "修改表格样式111", isComplete: false },
                  { item: "完善弹窗111", isComplete: false },
                ],
                endDate: "2021-08-20",
                endTime: "",
                isUrgent: true,
                isImportant: false,
                isComplete: false,
              },
            ],
            doing: [],
            done: [],
          },
        },
      ],
    };
  },
  methods: {
    handleSelect: function (index) {
      // console.log(index, this.activeIndex, this.todoList);
      this.activeIndex = index;
      // console.log(this.todoList[this.activeIndex].content.todo);
    },

    // 点亮（开启）卡片
    openCard: function (idx) {
      // console.log(idx);
      let { todo, doing } = this.todoList[this.activeIndex].content;
      doing.unshift(todo[idx]);
      todo.splice(idx, 1);
    },

    // 熄灭（关闭）卡片
    closeCard: function (idx) {
      console.log(idx);
      let { todo, doing } = this.todoList[this.activeIndex].content;
      todo.unshift(doing[idx]);
      doing.splice(idx, 1);
    },

    // 勾选doing或done列表的父项时切换状态
    farCheckChange: function (type, idx) {
      let { doing, done } = this.todoList[this.activeIndex].content;
      if (type == "doing") {
        done.unshift(doing[idx]);
        doing.splice(idx, 1);
      } else if (type == "done") {
        doing.unshift(done[idx]);
        done.splice(idx, 1);
      }
    },

    // 归档卡片
    archiveCard: function (idx) {
      let { done } = this.todoList[this.activeIndex].content;
      done.splice(idx, 1);
    },

    // 消息提示
    msg: function (str, type) {
      this.$message({
        message: str,
        type,
      });
    },
  },
};
</script>

<style lang="less" src="../assets/css/views/memo.less">
// 加了scoped，修改的element-ui样式会失效
</style>
